#include "uniform_time.h"

using std::string;

#if defined(__linux__) || defined(__APPLE__)

#include <sys/time.h>

std::string GetCurrentTime() {
	timeval curTime;
	gettimeofday(&curTime, nullptr);
	int milli = curTime.tv_usec / 1000;

	char buffer[80];
	strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", localtime(&curTime.tv_sec));

	char currentTime[84] = "";
	sprintf(currentTime, "%s.%d", buffer, milli);
	return string(currentTime);
}

#else

std::string GetCurrentTime() {
	SYSTEMTIME sysTime;
	GetLocalTime(&sysTime);
	char timeStr[30];
	sprintf(timeStr, "%d-%d-%d %d:%d:%d.%d", 
		sysTime.wYear, sysTime.wMonth, sysTime.wDay,
		sysTime.wHour, sysTime.wMinute, sysTime.wSecond, sysTime.wMilliseconds);
	return string(timeStr);
}

#endif